home *** CD-ROM | disk | FTP | other *** search
- Path: yarrina.connect.com.au!usenet
- From: Andrew Dalgleish <andrewd@axonet.com.au>
- Newsgroups: comp.lang.c
- Subject: Re: HELP: Illegal Pointer Arithmetic
- Date: Tue, 27 Feb 1996 18:52:17 +1000
- Organization: Axon Research, Pty Ltd
- Message-ID: <3132C641.1D1B@axonet.com.au>
- References: <4gj0ug$730@news.one.net> <danpop.825121139@rscernix> <31306a18.309961701@nntp.ix.netcom.com> <4gq77b$bmo@reznor.larc.nasa.gov> <4gqija$bmo@reznor.larc.nasa.gov>
- NNTP-Posting-Host: 203.63.6.118
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Ed Hook wrote:
- > Blair Houghton gently pointed out to me (_via_ e-mail) that the above
- > defense of Schildt is *erroneous*, since the code in question fails on
- > an _empty_ input file. Overall, I feel somehow _cleaner_ now ...
-
- do {
- ch = fgetc(fp);
- /* ... */
- } while (!feof(fp));
-
- This may fail for more than just empty files!
- The function fgetc() returns an int.
- If ch is a char it fails.
- If ch is an int, AND you test for EOF, it's ok.
- The old problem of trying to return two things in one value.
-
- int iChar; /* int to hold EOF */
- do {
- /* get char cast to int or EOF if at end-of-file */
- iChar = fgetc(fp);
- /* Test for end-of-file */
- if (iChar != EOF) {
- /* ... */
- }
- } while (!feof(fp));
-
- I wish my mailer had bracket matching and syntax checking :)
-
- --
- Andrew Dalgleish
- Senior Software Engineer
- Axon Research, Pty Ltd
- 6 Wallace Ave
- Toorak, VIC
- 3142
- AUSTRALIA
- Tel: +61-3-9826-5538
- Fax: +61-3-9824-0083
- Email: andrewd@axonet.com.au
-